home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / amiga / bmake15.lzh / depend.c < prev    next >
C/C++ Source or Header  |  1991-09-09  |  3KB  |  148 lines

  1. /*    depend.c
  2.  *    (c) Copyright 1991 by Ben Eng, All Rights Reserved
  3.  *
  4.  */
  5.  
  6. #include <clib/exec_protos.h>
  7.  
  8. #include "make.h"
  9. #include "depend.h"
  10.  
  11. struct target *default_target = NULL;
  12.  
  13. struct target *
  14. find_target( char *targetname )
  15. {
  16.     struct target *targ = NULL;
  17.  
  18.     for( struct target *ln = Global.targetlist.lh_Head; ln->node.ln_Succ;
  19.         ln = ln->node.ln_Succ ) {
  20.         if( !stricmp( targetname, ln->name )) {
  21.             targ = ln;
  22.             break;
  23.         }
  24.     }
  25.  
  26.     return( targ );
  27. }
  28.  
  29. struct target *
  30. new_target( char *targetname )
  31. {
  32.     long size;
  33.     struct target *new = NULL;
  34.  
  35.     if( targetname && *targetname ) {
  36.         size = sizeof(struct target) + strlen( targetname );
  37.         new = (struct target *)malloc( size );
  38.         if( new ) {
  39.             NewList( &new->dependlist );
  40.             NewList( &new->commandlist );
  41.             new->alternate = NULL;
  42.             new->mtime = 0L;
  43.             new->flags = 0L;
  44.             if( targetname )
  45.                 strcpy( new->name, targetname );
  46.             else
  47.                 *targetname = (char)0;
  48.         }
  49.     }
  50.     return( new );
  51. }
  52.  
  53. int
  54. delete_target( struct target *targ )
  55. {
  56.     if( (targ->flags & TF_OWNER) && targ->commandlist.lh_Head )
  57.         delete_commandlist( &targ->commandlist );
  58.     if( targ->dependlist.lh_Head )
  59.         delete_dependlist( &targ->dependlist );
  60.     free( targ );
  61.     return( 0 );
  62. }
  63.  
  64. void
  65. delete_targetlist( struct List *list )
  66. {
  67.     for_list( list, delete_target );
  68.     NewList( list );
  69. }
  70.  
  71. void
  72. set_default_target( struct target *targ )
  73. {
  74.     if( default_target ) {
  75.         delete_target( default_target );
  76.     }
  77.     default_target = targ;
  78.     debugprintf( 4, ( "Setting .DEFAULT target\n" ));
  79. }
  80.  
  81. struct depend *
  82. new_depend( char *dependname )
  83. {
  84.     struct depend *new = NULL;
  85.     long size;
  86.  
  87.     if( dependname ) {
  88.         size = sizeof(struct depend) + strlen( dependname );
  89.         if( new = (struct depend *)malloc( size )) {
  90.             strcpy( new->name, dependname );
  91.         }
  92.     }
  93.     return( new );
  94. }
  95.  
  96. int
  97. delete_depend( struct depend *dep )
  98. {
  99.     free( dep );
  100.     return( 0 );
  101. }
  102.  
  103. void
  104. delete_dependlist( struct List *list )
  105. {
  106.     for_list( list, delete_depend );
  107.     NewList( list );
  108. }
  109.  
  110. struct command *
  111. new_command( char *cmd )
  112. {
  113.     long size;
  114.     struct command *new = NULL;
  115.     if( cmd && *cmd ) {
  116.         size = sizeof(struct command) + strlen( cmd );
  117.         new = (struct command *)malloc( size );
  118.         if( new ) {
  119.             if( *cmd == '-' ) {
  120.                 new->flags = CF_IGNORE;
  121.                 cmd++;
  122.             }
  123.             else if( *cmd == '@' ) {
  124.                 new->flags = CF_NOECHO;
  125.                 cmd++;
  126.             }
  127.             else new->flags = 0;
  128.             strcpy( new->cmd, cmd );
  129.         }
  130.     }
  131.     return( new );
  132. }
  133.  
  134. int
  135. delete_command( struct command *cmd )
  136. {
  137.     free( cmd );
  138.     return( 0 );
  139. }
  140.  
  141. void
  142. delete_commandlist( struct List *list )
  143. {
  144.     for_list( list, delete_command );
  145.     NewList( list );
  146. }
  147.  
  148.